package summary;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: 海琳琦
 * @Date: 2022/6/8 15:25
 * https://leetcode.cn/problems/pascals-triangle/
 */
public class Title118 {

    public List<List<Integer>> generate(int numRows) {
        //[0....i]
        //..
        //..
        //[numRows-1...i]
        int[][] arr = new int[numRows][];
        //初始化
        for (int i = 0; i < numRows; i++) {
            //动态初始化
            arr[i] = new int[i + 1];
            arr[i][0] = 1;
            arr[i][i] = 1;
        }
        for (int i = 2; i < numRows; i++) {
            for (int j = 1; j < i; j++) {
                arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
            }
        }
        List<List<Integer>> result = new ArrayList<>();
        for (int i = 0; i < numRows; i++) {
            List<Integer> temp = new ArrayList<>();
            for (int j = 0; j <= i; j++) {
                temp.add(arr[i][j]);
            }
            result.add(temp);
        }
        return result;
    }

    public static void main(String[] args) {

    }
}
